﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using EM.utility;
using System.Data;

namespace EM.Common
{
    public partial class EditHeader : System.Web.UI.UserControl
    {

        public string TableName { get; set; }
        public int HEADERID { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(TableName) && HEADERID > 0)
            {
                string str = "";
                str += " SELECT TN.CREDATE ,TN.CREUSER ,TN.MODUSER, TN.MODDATE FROM [$TABLENAME] TN";
                str += " WHERE TN.[$TABLEUNIQUEID] = @UNIQUEID ";

                str = str.Replace("[$TABLENAME]", TableName);
                string unique = TableName.Replace("TBL", "") + "ID";
                str = str.Replace("[$TABLEUNIQUEID]", unique);

                SqlCommand cmd = new SqlCommand();
                cmd.CommandText = str;
                cmd.Parameters.AddWithValue("@UNIQUEID", HEADERID);

                DataSrv srv = new DataSrv();

                DataTable dt = srv.CreateDataTable(cmd, "TBL");
                if (dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["CREDATE"].ToString() != "")
                        txtCREDATE.Text = Convert.ToDateTime(dt.Rows[0]["CREDATE"]).ToShortDateString();
                    txtCREUSERE.Text = dt.Rows[0]["CREUSER"].ToString();
                    if (dt.Rows[0]["CREDATE"].ToString() != "")
                        txtMODDATE.Text = Convert.ToDateTime(dt.Rows[0]["MODDATE"]).ToShortDateString();
                    txtMODUSER.Text = dt.Rows[0]["MODUSER"].ToString();
                }
            }
        }
    }
}